// ToyWorklistDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ToyWorklistDlg.h"
#include "afxdialogex.h"

#include "Taurus_Common/IAppGlobalInstanceSet.h"
#include "Taurus_Common/MonitorAdmin.h"
#include "Taurus_Common/Monitor.h"
#include "Taurus_Common/IViewerModule.h"

#include "Taurus_Worklist/ToyWorklist.h"

// CToyWorklistDlg dialog

IMPLEMENT_DYNAMIC(CToyWorklistDlg, CDialogEx)

CToyWorklistDlg::CToyWorklistDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CToyWorklistDlg::IDD, pParent)
{

}

CToyWorklistDlg::~CToyWorklistDlg()
{
}

void CToyWorklistDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CToyWorklistDlg, CDialogEx)
  ON_WM_CLOSE()
END_MESSAGE_MAP()


// CToyWorklistDlg message handlers


void CToyWorklistDlg::OnClose()
{
  CRect rcWindow;
  GetWindowRect(&rcWindow);
  CPoint ptCenter = rcWindow.CenterPoint();

  IAppGlobalInstanceSet* pAGSet = CToyWorklist::getAppGlobalInstanceSet();
  CMonitorAdmin* pMA = pAGSet->getMonitorAdmin();
  const CMonitor* pMonitor = pMA->findMonitorIf(
    [&ptCenter](const CMonitor* pMonitor)
  {
    CRect rcWork = pMonitor->getWorkRect();
    return rcWork.PtInRect(ptCenter);
  });

  ShowWindow(SW_HIDE);

  //request viewer to show viewer
  IViewerModule* pViewer = pAGSet->getViewer();
  pViewer->ShowViewer(pMonitor);
}
